﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NoteHelper.BaseControl
{
    public class Helper4ComboBox : IControlHelper
    {
        public object GetValue(Control control)
        {
            var cbb = (ComboBox)control;
            return cbb.SelectedValue;
        }

        public void SetValue(Control control, object value)
        {
            var cbb = (ComboBox)control;
            if (value == null)
            {
                cbb.SelectedIndex = -1;
                return;
            }
            cbb.SelectedValue = value;
            //var index = cbb.Items.IndexOf(value);
            //foreach (var item in cbb.Items)
            //{
            //    var row = item as DataRowView;

            //    if (row != null && row.Row["id"].ToString() == value.ToString())
            //    {
            //        index = cbb.Items.IndexOf(item);
            //    }
            //}
            //cbb.SelectedIndex = index;
        }
    }
}
